<@pp.dropOutputFile/>
<#include "../common/util.ftl">
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign app = doc.artifactid?replace(".", "/")>
<#assign package = table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name = "/" + package  + "/View/" + fileName + "Control.vb"/>
<#assign package = table.moduleid?replace("/", ".")>
Imports Stone
Imports ${app}.${package}

Public Class ${fileName}Control
	Public Delegate Sub ButtonClickHandle(sender As Object, e As EventArgs)
    Public Event MoreButtonClicked As ButtonClickHandle

    Public Function GetParameters() As ${fileName}
        Dim res = New ${fileName}() With{
        <#list table.fields as field>
			<#if isText(field.type)>
			.${field.name?cap_first} = TextBoxX_${field.name?cap_first}.Text<#if field_has_next>,</#if>
			</#if>
			<#if isInteger(field.type)>
			.${field.name?cap_first} = IntegerInput_${field.name?cap_first}.Value<#if field_has_next>,</#if>
			</#if>
			<#if isReal(field.type)>
			.${field.name?cap_first} = DoubleInput_${field.name?cap_first}.Value<#if field_has_next>,</#if>
			</#if>
			<#if isDate(field.type)>
			.${field.name?cap_first} = DateTimeInput_${field.name?cap_first}.Value<#if field_has_next>,</#if>
			</#if>
		</#list>
		}
		
        Return res
    End Function

    Public Function IsValid() As Boolean
        Return True
    End Function

    Public Sub LoadDefault()
       <#list table.fields as field>
		<#if isText(field.type)>
		TextBoxX_${field.name?cap_first}.Text = "<#if field.def??>${field.def}</#if>"
		</#if>
		<#if isInteger(field.type)>
		IntegerInput_${field.name?cap_first}.Text = "<#if field.def??>${field.def}</#if>"
		</#if>
		<#if isReal(field.type)>
		DoubleInput_${field.name?cap_first}.Text = "<#if field.def??>${field.def}</#if>"
		</#if>
		<#if isDate(field.type)>
		DateTimeInput_${field.name?cap_first}.Text = "<#if field.def??>${field.def}</#if>"
		</#if>
	</#list>
    End Sub

    Public Sub LoadParameters(data As ${fileName})
        Try
		<#list table.fields as field>
			<#if isText(field.type)>
			TextBoxX_${field.name?cap_first}.Text = data.${field.name?cap_first}
			</#if>
			<#if isInteger(field.type)>
			IntegerInput_${field.name?cap_first}.Text = data.${field.name?cap_first}
			</#if>
			<#if isReal(field.type)>
			DoubleInput_${field.name?cap_first}.Text = data.${field.name?cap_first}
			</#if>
			<#if isDate(field.type)>
			DateTimeInput_${field.name?cap_first}.Text = data.${field.name?cap_first}
			</#if>
		</#list>
        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try
    End Sub

    Private Sub ButtonX_More_Click(sender As System.Object, e As System.EventArgs) Handles ButtonX_More.Click
        RaiseEvent MoreButtonClicked(sender, New EventArgs())
    End Sub


    Private Sub ButtonX_Default_Click(sender As System.Object, e As System.EventArgs) Handles ButtonX_Default.Click
        LoadDefault()
    End Sub
	
End Class
</#list>